<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
    <title>美策平台</title>
    <link rel="icon" type="image/png" href="/img/icon.png">
    <link rel="stylesheet" type="text/css" href="../datepicker/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="../css/app.css">
    <link rel="stylesheet" type="text/css" href="../css/orderGrad.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="/h5/js/all.js"></script>

</head>
<body>
    <!-- 我的订单（抢单和订单） -->
    <div class="orderDockingPage">
        <div class="orderParamTitle">
            订单对接
            <a href="/h5/myset.html"> <img src="../images/return.png" class="orderRtns" ></a>
        </div>
        <div style="height:1.066667rem"></div>
        <div class="content">
            <ul class="list myOrderList">
            </ul>
        </div>
    </div>
    <script type="text/javascript" src="../js/app.js"></script>
    <script type="text/javascript" src="../js/orderPageChange.js"></script>
    <script type="text/javascript" src="../js/alertMsg.js"></script>
    <script>
      $('.orderDockingPage .detail').click(function() {
          window.location.href = 'orderProductionDocumentary.html'
      })
    </script>
</body>
</html>
<script>
    var userInfo = JSON.parse(localStorage.getItem('userInfo'));
    var app_access = userInfo.app_access;
    var token = userInfo.token;
    function changeOrder(id,type) {
        var data = {
            id: id,
            app_access: app_access,
            token: token,
            type: type
        }
        $.ajax({
            url: '/api/order/my/update',
            data: data,
            type: 'post',
            dataType: 'json',
            success: function(data) {
                if(data.code < 0){
                    alertMsg(data.msg)
                }else{
                    alertMsg(data.msg)
                    window.location.href='orderDocking.html'
                }
            },
            err: function(err) {
                alertMsg(err)
            }
        })
    }
    $(function() {
        getOrderList();
        function getOrderList() {
            var data = {
                app_access: app_access,
                token: token
            }
            $.ajax({
                url: '/api/order/my/get',
                data: data,
                type: 'get',
                dataType: 'json',
                success: function(data) {
                    if (!data.data) {
                        alertMsg('暂无数据')
                        return false
                    }
                    var listHtml = '';
                    var status = '';
                    var order_status = '';
                    data = data.data;
                    if (data == undefined) {
                        return false
                    }
                    for (var i = 0; i < data.length; i++) {
                        var id = data[i].id;
                        if(data[i].type == 1){ //抢单
                            //$item['status'] = 0; //生产订单的流程状态 0 不显示
                            //$item['order_status'] = $t['status']; //抢单中还是生产中  1未支付，2已支付未抢单，3抢单中，4抢单成功  5抢单失败
                            //$item['is_del'] = $t['order_detail']['del']; // 1删除（已取消）
                            if(data[i].is_del == 1){
                                status = '已取消';
                                order_status = '';
                            }else if(data[i].order_status == 1){
                                if(data[i].out_trade_no!==''){
                                    order_status = '<a href="/h5/order/orderPayType.html?out_trade_no='+data[i].out_trade_no+'">去支付</a>';
                                }else{
                                    order_status = '<a  >订单失效</a>';
                                }
                                status = '未支付';

                            }else if(data[i].order_status == 2){
                                status = '已支付未抢单';
                                if(data[i].out_trade_no!==''){
                                    order_status = '<a href="/h5/order/orderPayType.html?out_trade_no='+data[i].out_trade_no+'">去支付</a>';
                                }else{
                                    order_status = '<a  >订单失效</a>';
                                }
                            }else if(data[i].order_status == 3){
                                status = '抢单中';
                                order_status = '商务交流';
                            }else if(data[i].order_status == 4){
                                status = '抢单成功';
                                order_status = '';
                            }else if(data[i].order_status == 5){
                                status = '<span style="color:red;">抢单失败</span>';
                                order_status = '';
                            }
                        }else{ //我的订单
                            ////订单状态：1未发原料，2接收原料，3生产中，4客户跟单，5确认跟单，6打包发货，7到货签收，8评价,9已完成
                            if(data[i].is_del == 1){
                                status = '已取消';
                                order_status = '';
                            }else if(data[i].status == 1){
                                status = '待生产';
                                order_status = '未发原料';
                            }else if(data[i].status == 2){
                                status = '待生产';
                                order_status = '<span onclick="changeOrder('+id+',2)">接收原料</span>';
                            }else if(data[i].status == 3){
                                status = '生产中';
                                order_status = '';
                            }else if(data[i].status == 4){
                                status = '生产中';
                                order_status = '<a href="orderProductionDocumentary.html?id='+data[i].id+'">跟单开始</a>';
                            }else if(data[i].status == 5){
                                status = '生产中';
                                order_status = '<a href="orderProductionDocumentary.html?id='+data[i].id+'">确认跟单</a>';
                            }else if(data[i].status == 6){
                                status = '运输中';
                                order_status = '<a href="shippingTransportation.html?id='+data[i].id+'">打包发货</a>';
                            }else if(data[i].status == 7){
                                status = '运输中';
                                order_status = '<a href="shippingTransportation.html?id='+data[i].id+'">确认签收</a>';
                            }else if(data[i].status == 8){
                                status = '待评价';
                                order_status = '<a href="shippingOrderEvaluate.html?id='+data[i].id+'">马上评价</a>';
                            }else if(data[i].status == 9){
                                status = '已完成';
                                order_status = '';
                            }
                        }
                        listHtml += "<li class=\"detail\">\n" +
                            "                    <span class=\"detail__span\" style=background-image:url("+data[i].img+") alt=\"\"></span>                   \n" +
                            "                    <ul>\n" +
                            "                        <li>\n" +
                            "                            <span>订单名称：</span>\n" +
                            "                            <span>"+data[i].title+"</span>\n" +
                            "                            <span>"+status+"</span>\n" +
                            "                        </li>\n" +
                            "                        <li  data-id="+data[i].id+">\n" +
                            "                            <span>客户公司：</span>\n" +
                            "                            <span>"+data[i].company+"</span>\n" +
                            "                            <span>"+order_status+"</span>\n" +
                            "                        </li>\n" +/*
                            "                        <li>\n" +
                            "                            <span>下单时间：</span>\n" +
                            "                            <span>"+data[i].addtime+"</span>\n" +
                            "                             \n" +
                            "                        </li>\n" +*/
                            "                        <li>\n" +
                            "                            <span>交货期限：</span>\n" +
                            "                            <span>"+data[i].exptime+"</span>\n" +
                            "                        </li>\n" +
                            "                    </ul>\n" +
                            "                </li>";
                    }
                    $(".myOrderList").html(listHtml);
                },
                err: function(err) {
                    alertMsg(err)
                }
            })
        }
    })
</script>